package Week3.J0504;

// 双指针模拟

public class 压缩字符串一 {
    public String compressString (String str) {
        int left = 0;
        int right = 0;
        StringBuilder sbr = new StringBuilder();
        while (right < str.length()) {
            if (right + 1 < str.length() && str.charAt(right) == str.charAt(right + 1)) {
                right++;
            }else {
                int tmp = right - left + 1;
                sbr.append(str.charAt(left));
                if (tmp > 1) {
                    sbr.append(tmp);
                }
                left = right + 1;
                right++;
            }
        }
        return sbr.toString();
    }
}
